package com.walter.runner;

import cn.hutool.system.SystemUtil;
import com.walter.service.DictService;
import com.walter.service.MenuService;
import com.walter.service.RoleService;
import com.walter.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author ：ch
 * @date ：Created in 2021/5/25
 * @description：
 * @modified By：
 * @version: 1.0
 */
@Component
@Slf4j
public class SystemRunner implements ApplicationRunner {
    @Autowired
    private DictService dictService;

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 缓存字典表数据,提升查询性能
        dictService.setSystemDictCache();
        // 初始化内置角色
        if (roleService.initBuiltinRoles()) log.info("init built-in roles succeed");
        // 初始化admin
        if (userService.initAdmin()) log.info("init user[admin] succeed");
        // initMenus
        if (menuService.initMenus() > 0) log.info("init user[admin]'s menus succeed");

        log.info("OS is {}.", SystemUtil.getOsInfo().getName());
        log.info("java.io.tmpdir is {}",System.getProperty("java.io.tmpdir"));
    }
}
